<template>
  <!-- 荷官聊天 -->
  <el-dialog :visible.sync="isShow" v-if="isShow" title="荷官聊天信息" width="50%" :before-close="handleClose" top="100px" :close-on-click-modal="false">
    <div class="border-box">
      <el-form ref="dealerForm" :model="formParams" :rules="ruleForm" label-position="right" label-width="0">
        <div class="flex item-box" v-for="(item,index) in itemData" :key="index">
          <div class="title width25">
            {{ item.label }}<span :class="item.pass?'mustPass':'noMustPass'">*</span>
          </div>
          <div class="content width80">
            <el-form-item class="item-clear" v-show="item.key=='game_id'" label="" prop="game_id">
              <el-select v-model="formParams.game_id" placeholder="请选择游戏类型" filterable disabled>
                <el-option label="公共数据" :value="0"></el-option>
                <el-option :label="item.label" :value="item.value" v-for="(item, index) in GAME_TYPE" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_base_croupier_chat_id'" label="" prop="a_base_croupier_chat_id">
              <el-input-number :min="0" :precision="0" v-model="formParams.a_base_croupier_chat_id" controls-position="right" clearable placeholder="请输入荷官聊天聊天ID" />
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_croupier_chat_remark'" label="" prop="a_croupier_chat_remark">
              <el-input class="width40" type="text" v-model="formParams.a_croupier_chat_remark" clearable placeholder="请输荷官聊天备注"/>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='condition_itemType'" label="" prop="condition_itemType">
              <el-select v-model="condition_itemType" placeholder="请选择荷官聊天条件" filterable>
                <el-option :label="second.label" :value="second.value" v-for="(second,two) in conditionType" :key="two"></el-option>
              </el-select>
              <el-input-number :min="0" :max="999999999" :precision="0" v-model="formParams.condition_num" controls-position="right" clearable placeholder="请输入参数"/>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='multilingual'" label="" prop="multilingual">
              <el-select class="width200" v-model="formParams.multilingual" placeholder="请选择多语言" multiple  filterable>
                <el-option :label="'【'+ item.value+ '】' + item.label" :value="item.value" v-for="(item, index) in languageDataList" :key="index"></el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="medium" @click="handleClose">取 消</el-button>
      <el-button size="medium" type="primary" @click="handleConfirm('dealerForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  addDealer,
  editDealer
} from '@/api/game'
import {
  GAME_TYPE
} from '@/utils/enum'
export default {
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: function () {
        return {}
      }
    },
    gameType: {
      type: Number,
      default: 1
    },
    conditionType: {
      type: Array,
      default: function () {
        return []
      }
    },
    languageDataList: {
      type: Array,
      default: function () {
        return []
      }
    },
  },
  data () {
    return {
      GAME_TYPE,
      isShow: false,
      itemData:[
        {label:'游戏类型',key:'game_id'},
        {label:'荷官聊天ID',key:'a_base_croupier_chat_id',pass:true},
        {label:'备注',key:'a_croupier_chat_remark'},
        {label:'聊天条件',key:'condition_itemType'},
        {label:'多语言',key:'multilingual'},
      ],
      formParams: {
        game_id:this.gameType,
        a_base_croupier_chat_id: 0, //快捷聊天id
        a_croupier_chat_remark: '', //备注
        a_croupier_chat_text: '', //多语言
        a_base_croupier_chat_condition: '', // 多个条件用分号隔开
        multilingual: [],
        condition_num: 0,
      },
      condition_itemType: 1,
      ruleForm: {
        a_base_croupier_chat_id: [{ required: true, trigger: 'blur', message: '请输入荷官聊天ID', }],
      },
      conditionData: [
        {itemType:1,num:0}
      ],
    }
  },
  computed: {},
  watch: {
    show: function () {
      let that = this;
      that.isShow = that.show
      if (that.data) {
        that.formParams = JSON.parse(JSON.stringify(that.data))
        that.condition_itemType=Number(that.formParams.condition[0])
        that.formParams.condition_num=Number(that.formParams.condition[1])
      } else {
        that.formParams = {
          game_id:this.gameType,
          a_base_croupier_chat_id: 0, //快捷聊天id
          a_croupier_chat_remark: '', //备注
          a_base_croupier_chat_condition: '', // 多个条件用分号隔开
          a_croupier_chat_text: '', // 多个条件用分号隔开
          multilingual: [],
          condition_itemType: 1,
          condition_num: 0,
        }
      }
    },
  },
  mounted () {},
  methods: {
    // 确认
    handleConfirm (formvalue) {
      let that = this, params = JSON.parse(JSON.stringify(that.formParams));
      params.a_base_croupier_chat_condition=that.condition_itemType+','+params.condition_num
      params.a_croupier_chat_text=params.multilingual.join(';')
      that.$refs[formvalue].validate((valid) => {
        if (valid) {
          // 新增
          if (!params.id) {
            addDealer(params).then(function (res) {
              that.$message.success(res.msg)
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          } else {
            editDealer(params).then(function (res) {
              that.$message.success(res.msg)
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          }
        } else {
          return false;
        }
      });
    },
    // 取消
    handleClose () {
      this.$emit('onHideDetails', false)
    },
  }
}
</script>

<style scoped lang="scss">
.btn-box-add {
  width: 50px;
  margin-bottom: 20px;
  margin-right: -15px;
  text-align: center;
  .el-button {
    height: 28px;
  }
}
.btn-box-delete {
  width: 50px;
  margin-bottom: 20px;
  text-align: center;
  .el-button {
    height: 28px;
  }
}
</style>
